package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.SelectTemplateDao;
import com.x.erp.model.SelectTemplate;
import com.x.erp.rpc.SelectTemplateRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 订阅信息服务
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.SelectTemplateRpcService", timeout = 60000)
public class SelectTemplateService extends BaseService implements SelectTemplateRpcService {

	@Autowired
	private SelectTemplateDao selectTemplateDao; // 订阅Dao

	/**
	 * 新增订阅信息
	 * @param selectTemplate
	 * @return
	 */
	@Override
	public SelectTemplate insertSelectTemplate(SelectTemplate selectTemplate) {
		try {
			Date cDate = new Date();
			selectTemplate.setTemplateCreateTime(cDate);
			selectTemplate.setTemplateUpdateTime(cDate);
			return this.insert(selectTemplate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 删除订阅信息
	 * @param selectTemplate
	 * @return
	 */
	@Override
	public int deleteSelectTemplate(SelectTemplate selectTemplate) {
		try {
			return this.delete(selectTemplate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改订阅信息
	 * @param selectTemplate
	 * @return
	 */
	@Override
	public SelectTemplate updateSelectTemplate(SelectTemplate selectTemplate) {
		try {
			selectTemplate.setTemplateUpdateTime(new Date());
			int res = selectTemplateDao.updateSelectTemplate(selectTemplate);
			if(res == 1){
				return selectTemplate;
			}
			return null;
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询订阅信息
	 * @param selectTemplate
	 * @return
	 */
	@Override
	public SelectTemplate selectSelectTemplate(SelectTemplate selectTemplate) {
		try {
			return selectTemplateDao.selectSelectTemplate(selectTemplate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询订阅列表信息
	 * @param selectTemplate
	 * @return
	 */
	@Override
	public List<SelectTemplate> selectSelectTemplateList(SelectTemplate selectTemplate) {
		try {
			return selectTemplateDao.selectSelectTemplateList(selectTemplate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
